package com.jinlejia.erp.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.databinding.DataBindingUtil;
import androidx.recyclerview.widget.RecyclerView;

import com.freedom.yefeng.yfrecyclerview.YfListAdapter;
import com.freedom.yefeng.yfrecyclerview.YfSimpleViewHolder;
import com.jinlejia.erp.R;
import com.jinlejia.erp.bean.SearchHistoryBean;
import com.jinlejia.erp.bean.SearchHouseHistoryBean;
import com.jinlejia.erp.databinding.ItemSearchHouseResultBinding;

import java.util.ArrayList;


/**
 * 房源搜索历史Adapter
 * Created by Administrator on 2017/4/27 0027.
 */

public class SearchHistoryAdapter extends YfListAdapter {

    public SearchHistoryAdapter(ArrayList data) {
        super(data);
    }

    @Override
    public RecyclerView.ViewHolder onCreateDataViewHolder(ViewGroup parent) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_search_house_result, parent, false);
        //搜索结果
        return new HistoryViewHolder(view);
    }

    @Override
    public RecyclerView.ViewHolder onCreateEmptyViewHolder(ViewGroup parent) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.empty_layout, parent, false);
        TextView txt = view.findViewById(R.id.id_tips);
        txt.setText("暂无历史");
        return new YfSimpleViewHolder(view);
    }

    @Override
    public void onBindDataViewHolder(RecyclerView.ViewHolder holder, int position) {
        ItemSearchHouseResultBinding binding = DataBindingUtil.getBinding(holder.itemView);
        Object o = mData.get(position);
        if (o instanceof SearchHistoryBean){
            binding.tvHouseName.setText(((SearchHistoryBean) o).getName());
            binding.getRoot().setTag(mData.get(position));
        }else if (o instanceof SearchHouseHistoryBean){
            binding.tvHouseName.setText(((SearchHouseHistoryBean) o).getName());
            binding.getRoot().setTag(o);
        }
    }

    @Override
    public void onBindFooterViewHolder(RecyclerView.ViewHolder holder, int position) {
        super.onBindFooterViewHolder(holder, position);
    }

    @Override
    public RecyclerView.ViewHolder onCreateFooterViewHolder(ViewGroup parent) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.footer_clear_layout, parent, false);
        return new YfSimpleViewHolder(view);
    }

    static final class HistoryViewHolder extends RecyclerView.ViewHolder {

        public HistoryViewHolder(View itemView) {
            super(itemView);
            ItemSearchHouseResultBinding binding = DataBindingUtil.bind(itemView);
            binding.tvHouseArea.setVisibility(View.GONE);
        }
    }

}
